------------------ fgui require start ------------------
------------------  fgui require end  ------------------
local GuildNoticeSkin = Class("GuildNoticeSkin");

function GuildNoticeSkin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.btn_blackbackground.onClick:Add(self.onTouch_Btn_blackbackground, self);
    self.btn_cancel.onClick:Add(self.onTouch_Btn_cancel, self);
    self.btn_determine.onClick:Add(self.onTouch_Btn_determine, self);
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function GuildNoticeSkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.btn_blackbackground = com:GetChild("Btn_blackbackground");
    self.btn_cancel = com:GetChild("Btn_cancel");
    self.btn_determine = com:GetChild("Btn_determine");
    self.text_amendmentnotice = com:GetChild("Text_amendmentnotice");
    self.text_close = com:GetChild("Text_close");
    self.text_notice = com:GetChild("Text_notice");
    ------------------  fgui变量绑定end  ------------------
end

function GuildNoticeSkin:init()
    self.closeCallback = nil;
    self.text_notice.promptText = getLanguage("GuildInvestment_1097");
    self.text_notice.text = logicMgr.GuildManager.getUnionNotice();
    ListenEvent(Config.EventType.Union_UpdateSettingInfo_S2C, self.respUnionSetting, self);
end

function GuildNoticeSkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.btn_blackbackground.onClick:Clear();
    self.btn_cancel.onClick:Clear();
    self.btn_determine.onClick:Clear();
    ------------------  fgui事件移除end  ------------------
end

function GuildNoticeSkin:onTouch_Btn_blackbackground(obj)
    if self.closeCallback then
        self.closeCallback()
    end ;
end

function GuildNoticeSkin:onTouch_Btn_cancel(obj)
    if self.closeCallback then
        self.closeCallback()
    end ;
end

function GuildNoticeSkin:onTouch_Btn_determine(obj)
    local notice = string.trim(self.text_notice.text)
    local noticeNum = string.lenUtf8(self.text_notice.text)
    if #notice == 0 then
        UISysTips.AddMsg(getLanguage("GuildInvestment_1074"));
        return ;
    end

    if logicMgr.ChatManager.HasFilterBlockWord(notice) then
        UISysTips.AddMsg(getLanguage("UIFriend_ApplyMsgBlock"))
        return ;
    end
    local maxText = G.dataTable["t_guildpara"]["44"]["f_int_value"]
    if noticeNum > maxText then
        UISysTips.AddMsg(getLanguage("GuildInvestment_1147"));
        return ;
    end

    local infoSetting = clone(logicMgr.GuildManager.getUnionSetting());
    infoSetting.unionNotice = notice;
    local unionId = logicMgr.GuildManager.getUnionId();

    if ChatManager.HasFilterBlockWord(notice) then
        UISysTips.AddMsg(getLanguage("UIFriend_ApplyMsgBlock"))
    else
        unionHandler.reqModifyUnionSetting(logicMgr.GuildManager.getUnionId(), infoSetting);
    end
end

------------------  ↑ fgui事件句柄 ↑  ------------------

function GuildNoticeSkin:setCloseCallback(func)
    self.closeCallback = func;
end

function GuildNoticeSkin:respUnionSetting()
    if self.closeCallback then
        self.closeCallback()
    end ;
end

function GuildNoticeSkin:beforeDestroy()
    self.closeCallback = nil;
    CloseEvent(Config.EventType.Union_UpdateSettingInfo_S2C, self.respUnionSetting, self);
end

return GuildNoticeSkin;
